package org.aplombh.java.awcing.basic.basics.prefixSumAndDifferencen;

import java.util.Scanner;
import java.util.stream.IntStream;

/**
 * compute the prefix sum of the array
 */
public class PrefixSum_795 {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);

        int n = scanner.nextInt();
        int m = scanner.nextInt();

        int[] a = new int[n + 1];
        int[] s = new int[n + 1];

        IntStream.rangeClosed(1, n).forEach(i -> {
            a[i] = scanner.nextInt();
            // store the sum of first term (n-1)
            s[i] = s[i - 1] + a[i];
        });

        while (m-- != 0) {
            int l = scanner.nextInt();
            int r = scanner.nextInt();
            System.out.println(s[r] - s[l - 1]);
        }
    }
}
